# 前台购物

from base import _YamlHelper
from page import Page
from page.web_login_page import WebLoginPage


class ShoppingPage(Page):
    shopping_yaml = _YamlHelper().get_config_as_dict('niushop23\\page\\shopping.yaml')['WebShoppingPage']

    def web_shopping_page(self,name,pwd):
        '''登录账户'''
        driver = self._driver
        web_login_page = WebLoginPage(driver)
        web_login_page.web_login_page(name, pwd)

    def get_login_text(self):
        '''获取登录页面用户名输入框文本'''
        driver = self._driver
        nameinput_text = driver.get_attribute(self.shopping_yaml['GET_NAMEINPUT_TEXT'], 'placeholder')
        return nameinput_text

    def get_username_text(self):
        '''登录成功后获取用户名文本'''
        driver = self._driver
        user_name_text = driver.get_text(self.shopping_yaml['GET_USERNAME_TEXT'])
        return user_name_text

    def get_sale_number_text(self):
        '''搜索后获取销售量文本'''
        driver = self._driver
        sale_number_text = driver.get_text(self.shopping_yaml['GET_SALE_NUM_TEXT'])
        return sale_number_text

    def get_buy_in_now_text(self):
        '''获取立即购买文本'''
        driver = self._driver
        buy_now_text = driver.get_text(self.shopping_yaml['BUY_NOW_TEXT'])
        return buy_now_text

    def get_to_consignee_text(self):
        '''获取收货人信息文本'''
        driver = self._driver
        consignee_text = driver.get_text(self.shopping_yaml['GET_CONSIGNEE_TEXT'])
        return consignee_text

    def get_to_usebalance_text(self):
        '''获取使用余额文本'''
        driver = self._driver
        usebalance_text = driver.get_text(self.shopping_yaml['GET_USEBALANCE_TEXT'])
        return usebalance_text

    def login_button(self):
        '''初始界面登录按钮'''
        driver = self._driver
        driver.click(self.shopping_yaml['LOGON_BUTTON'])

    def search_goods(self):
        '''搜索商品填写名称'''
        driver = self._driver
        driver.type(self.shopping_yaml['INPUT_GOODSNAME'], 'iPhone12')
        driver.click(self.shopping_yaml['CLICK_SEARCH_BUTTON'])

    def check_goods_to(self):
        '''勾选商品切换到新页面'''
        driver = self._driver
        driver.click(self.shopping_yaml['ADD_GOODS_BUTTON'])
        driver.switch_to_window_by_index(2)
        driver.drag_scrollbar(400)

    def buy_in_now(self):
        '''立即购买按钮'''
        driver = self._driver
        driver.click(self.shopping_yaml['CLICK_BUY_NOW_BUTTON'])

    def write_buyer_message(self):
        '''填写买家留言信息'''
        driver = self._driver
        driver.drag_scrollbar(800)
        driver.type(self.shopping_yaml['BUYER_WORD_WRITE'],'23333')

    def submit_order(self):
        '''点击提交订单按钮'''
        driver = self._driver
        driver.click(self.shopping_yaml['CLICK_SUBMIT_ORDER'])

    def pay_money(self):
        '''立即支付按钮'''
        driver = self._driver
        driver.click(self.shopping_yaml['CLICK_PAYMENT_BUTTON'])
